<?php
namespace app\index\controller;
use think\Request;
use think\Controller;
use think\Db;

class Release extends CommonController
{
    public function publicPage()
    {

        return $this->fetch("publicPage");
    }

    public function upImg(Request $request)
    {
        $file = $request->post('image');
        $base64_image = str_replace(' ', '+', $file);
        //post的数据里面，加号会被替换为空格，需要重新替换回来，如果不是post的数据，则注释掉这一行
        if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image, $result)){
            //匹配成功
            if($result[2] == 'jpeg'){
                $image_name = uniqid().'.jpg';
                //纯粹是看jpeg不爽才替换的
            }else{
                $image_name = uniqid().'.'.$result[2];
            }
            $image_file = ROOT_PATH."public/static/picture/".$image_name;
            //服务器文件存储路径
            if (file_put_contents($image_file, base64_decode(str_replace($result[1], '', $base64_image)))){
                return '/meetTWO/public/static/picture/'.$image_name;
            }else{
                return false;
            }
        }else{
            return false;
        }
        return dump($file);

    }

    public function subPag($content,$title,$id){
        $id=getId($id);
        $res=Db::table('page')->insert(
            [
                "page_time" =>date("Y-m-d H:i:s"),
                "user_id"   =>$id,
                "page_title"=>$title,
                "page_content"=>$content
            ]
            );
        return $res;
    }
}
